<template>
  <div class="child1">
    <h3>子组件1</h3>
    <h4>乐器：{{ instrument }}</h4>
    <h4>篮球：{{ collections }} 个</h4>
    <h4 v-show="house1 > 0">获得父亲的一套房产，房子数：{{ house1 }}</h4>
    <button @click="getOne($parent)">拿到父亲的一套房产</button>
  </div>
</template>

<script setup lang="ts" name="Child1">
import { ref, watch } from "vue";
// 数据
let instrument = ref("钢琴");
let collections = ref(3);
let house1 = ref(0);

defineExpose({ instrument, collections });

function getOne(x: any) {
  x.house -= 1;
  house1.value += 1;
}

watch(house1, () => {
  if (house1.value > 4) {
    return (house1.value = 4);
  }
});
</script>

<style scoped>
.child1 {
  margin-top: 20px;
  background-color: skyblue;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px black;
}
</style>
